/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aexcasus.willem.eltonrmipull;

import interfaces.IEffectenbeurs;
import interfaces.IFonds;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Random;
import java.util.TimerTask;

/**
 *
 * @author willem, Aangepast door elton
 */
public class MockEffectenbeurs extends UnicastRemoteObject implements  IEffectenbeurs {
    
    IFonds[] fondsen;
    java.util.Timer myRandomTimer;
    Random r = new Random();
    private static final int TIMERTICK = 1000;
    
    public MockEffectenbeurs() throws RemoteException {
        fondsen = new IFonds[3];
        
        //Creeer fondsen
        IFonds GOOG = new MockFonds("Google", 50);
        IFonds MSOF = new MockFonds("Microsoft", 40);
        IFonds ORAC = new MockFonds("Oracle", 45);
        
        fondsen[0] = GOOG;
        fondsen[1] = MSOF;
        fondsen[2] = ORAC;
        
        myRandomTimer = new java.util.Timer();
        myRandomTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                //Timer code
                for(IFonds fonds: fondsen) {
                    MockFonds curFonds = (MockFonds) fonds;
                    curFonds.setKoers(r.nextInt(150)-r.nextInt(25));
                }
            }
        }, TIMERTICK , TIMERTICK
                );
    }

    @Override
    public IFonds[] getKoersen() throws RemoteException {
        return fondsen;
    }
    
}
